define(['app'], function(app) {
    'use strict';

    // 实例化方法
    var factory = function(Http) {

        //发起新品一览
        function get_data_list(result) {
            //发起新品一览
            if(HTTP_ISLOGIC) {
                result = '{"success":true,"msg":"","result":{"act":[{"act_id":"act_id_001","name":"新年促销","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","image":{"id":"001","image":"./img/upload/pro-img01.jpg"},"goods":{"id":"001","name":"扳手-大"}},{"act_id":"act_id_002","name":"新年促销","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","image":{"id":"002","image":"./img/upload/pro-img01.jpg"},"goods":{"id":"002","name":"扳手-小"}}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
            }
        }
        //参与新品一览
        function get_data_jionlist(result) {
            //发起新品一览
            if(HTTP_ISLOGIC) {
                result = '{"success":true,"msg":"","result":{"act":[{"order_id":"001","act_id":"1234","name":"促销","status":"活动中","prize_status":"等待抽奖","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","image":{"id":"001","image":"./img/upload/pro-img01.jpg"}},{"order_id":"001","act_id":"1234","name":"促销","status":"活动中","prize_status":"等待抽奖","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","image":{"id":"002","image":"./img/upload/pro-img01.jpg"}}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
            }
        }

        // 返回信息
        return {
            get_list: function(nPage, status, callback,calldone) {
                Http.post({
                        method: 'marketing.giving.getlist',
                        status: status
                    },
                    function(result) {
                        //请求成功
                        if(callback)
                            callback(get_data_list(result).result);
                    },
                    function(e) {
                        //请求异常
                    },
                    function() {
                        //请求完成，一般不做什么事情
                        if(calldone)
                    calldone();
                    });

            },
            get_jionlist: function(nPage, callback,calldone) {
                Http.post({
                        method: 'marketing.giving.jionlist',
                        nPage: nPage,
                    },
                    function(result) {
                        //请求成功
                        if(callback)
                            callback(get_data_jionlist(result).result);
                    },
                    function(e) {
                        //请求异常
                    },
                    function() {
                        //请求完成，一般不做什么事情
                        if(calldone)
                    calldone();
                    }
                );
            }
        };
    }

    factory.$inject = ['Http'];
    return app.registerService("Newpro_present", factory);

});